<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <script>
      // 1、js一共有多少种数据类型?
      // 八种
      // 字符串 String ；数字 Number ；布尔值 Boolean；未定义 Undefined
      // 空对象 Null；唯一值 Symbol；对象类型 object；
      


      // 2、js检测数据类型有哪些方法?
      // 方法
      // 1.typeof
      // 2.instanceof
      // 3.constructor
      // 4.Object.prototype.toString.call

      // 3、undefined和null的区别?	用typeof检测它们分别返回什么值?
      // 区别：
      // undefined
      // 声明变量但是没有对其赋值，表示无值（空的值）;
      // 函数默认返回值也是 Undefined；
      // 访问对象不存在属性的时候，返回Undefined；
      // null
      // 空值，空的对象，空的对象引用地址（指针
      // 用typeof检测它们分别返回 string和Object
      // 4、写出下列对应结果
      let str_4 = '0';
      console.log(str_4); //0
      let str1_4 = '';
      console.log(str1_4); //空格
      let str2_4 = ' ';
      console.log(str2_4); //空格
      let unde_4 = undefined;
      console.log(unde_4); //undefined
      let nu_4 = null;
      console.log(nu_4); //null
      let num_4 = 0;
      console.log(num_4); 0
      let num1_4 = -10;
      console.log(num1_4); -10

      Boolean(str_4);
      console.log(Boolean(str_4));//true
      Boolean(str1_4); 
      console.log(Boolean(str1_4));//false
      Boolean(str2_4);
      console.log(Boolean(str2_4));//true
      Boolean(unde_4);
      console.log(Boolean(unde_4));//false
      Boolean(nu_4);
      console.log( Boolean(nu_4));//false
      Boolean(num_4);
      console.log(Boolean(num_4));//false
      Boolean(num1_4);
      console.log(Boolean(num1_4));//true

      // 5、写出下列对应结果	注意：需要分别使用Number、String、toString去转换数据类型
      let str_5 = '0';
      console.log(Number (str_5));//0
      console.log(String (str_5));//0
      console.log(str_5.toString ());//0
      let num_5 = -10;
      console.log(Number (num_5));//-10
      console.log(String (num_5));//-10
      console.log(num_5.toString ());//-10
      let flag_5 = true;
      console.log(Number (flag_5));//1
      console.log(String (flag_5));//true
      console.log(flag_5.toString ());//true
      let ud_5 = undefined;
      console.log(Number (ud_5));//NaN
      console.log(String (ud_5));//undefined
      // console.log(ud_5.toString ());//不可转换
      let nu_5 = null;
      console.log(Number (nu_5));//0
      console.log(String (nu_5));//null
      // console.log(nu_5.toString ());//不可转换

      // 6、检测下面的变量各自的数据类型
      let str_6 = '';
      console.log(typeof str_5);//string
      let num_6 = '-10';
      console.log(typeof num_6);//string
      let num1_6 = 0;
      console.log(typeof num1_6);//Number
      let nu_6 = undefined;
      console.log(typeof nu_6);//undefined
      let nu1_6 = 'undefined';
      console.log(typeof nu1_6);//string
      let nu2_6 = 'null';
      console.log(typeof nu2_6);//string
      let nu3_6 = null;
      console.log(typeof nu3_6);//Object
      let obj_6 = '{}';
      console.log(typeof obj_6);//string
      let obj1_6 = {};
      console.log(typeof obj1_6);//Object
      let sy_6 = Symbol('n');
      console.log(typeof sy_6);//Symbol
    </script>
  </body>
</html>
